//
//  YTMoneyDetailFilterView.m
//  YiTuDriverClient
//
//  Created by 石少庸 on 2017/8/15.
//  Copyright © 2017年 Yitu. All rights reserved.
//

#import "YTMoneyDetailFilterView.h"
#import "YTPickerView.h"

@interface YTMoneyDetailFilterView ()

@property (weak, nonatomic) IBOutlet UIButton *endTime;
@property (weak, nonatomic) IBOutlet UIButton *startTime;
@property (weak, nonatomic) IBOutlet UITextField *orderNum;

@end

@implementation YTMoneyDetailFilterView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self loadUserinterface];
    }
    return self;
}

/** 加载view*/
- (void)loadUserinterface {
    UIView *filter = [[NSBundle mainBundle] loadNibNamed:@"YTMoneyDetailFilterView" owner:self options:nil].firstObject;
    filter.frame = self.bounds;
    [self addSubview:filter];
}


- (IBAction)selectTime:(UIButton *)sender {
    [self endEditing:YES];
    YTPickerView *picker = [YTPickerView pickerWithType:YTPickerTypeMonthDay];
    picker.dimmedMask = YES;
    picker.birthday = YES;
    picker.completion = ^(NSString *selectString) {
        [sender setTitle:selectString forState:UIControlStateNormal];
    };
    [picker show];
}

- (IBAction)resetAction:(UIButton *)sender {
    [_startTime setTitle:@"开始时间" forState:UIControlStateNormal];
    [_endTime setTitle:@"结束时间" forState:UIControlStateNormal];
    _orderNum.text = nil;
    if (_resetAction) {
        _resetAction();
    }
}

- (IBAction)completeAction:(UIButton *)sender {
    if (_completeAction) {
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        dict[@"addTimeBegin"] = _startTime.currentTitle;
        dict[@"addTimeEnd"] = _endTime.currentTitle;
        if (_orderNum.text.length) {
            dict[@"orderId"] = _orderNum.text;
        }
        _completeAction(dict);
    }
    
}
@end
